class Solution(object):
    def bitwiseComplement(self, n):
        """
        :type n: int
        :rtype: int
        """
        index = 0
        k = 0
        while index < 32:
            if n >> index & 1 == 1:
                k = index
            index += 1
        return n ^ ((1 << (k + 1)) - 1)


data = Solution()
n = 5
print(data.bitwiseComplement(n))
